﻿#include<iostream>
using namespace std;

const int N = 100007;
string map[N];
int n, m, flag;
int ans1, ans2;

bool in(int i, int j)
{
	return i >= 0 && i < n && j >= 0 && j < m;
}

void dfs(int i, int j)
{
	if (!in(i, j) || map[i][j] == '0')return;
	if (map[i][j] > '1')flag = 1;
	map[i][j] = '0';
	dfs(i - 1, j);
	dfs(i, j - 1);
	dfs(i + 1, j);
	dfs(i, j + 1);
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> map[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (map[i][j] > '0') {
				flag = 0;
				dfs(i, j);
				ans1++;
				ans2 += flag;
			}
	cout << ans1 << " " << ans2;
	return 0;
}